package com.zzs.library.controller;

import com.zzs.library.common.api.CommonPage;
import com.zzs.library.common.api.CommonResult;
import com.zzs.library.nosql.elasticsearch.document.EsBook;
import com.zzs.library.service.EsBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author ZechariahZheng
 * @Date 2020/1/7 10:00
 * @Version 1.0
 * @description 搜索小说管理Controller
 */
@Controller
@Api(tags = "EsBookController", description = "搜索小说管理")
@RequestMapping("/esBook")
public class EsBookController {
    @Autowired
    private EsBookService esBookService;

    @ApiOperation(value = "简单搜索")
    @GetMapping("/search/simple")
    @ResponseBody
    public CommonResult<CommonPage<EsBook>> search(@RequestParam(required = false) String keyword,
                                                   @RequestParam(required = false, defaultValue = "0") Integer pageNum,
                                                   @RequestParam(required = false, defaultValue = "5") Integer pageSize) {
        Page<EsBook> esBookPage = esBookService.search(keyword, pageNum, pageSize);
        return CommonResult.success(CommonPage.resetPage(esBookPage));
    }
}
